package com.tesis_2.UI;

import java.util.ArrayList;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MORestaurant;
import com.tesis_2.Utils.UTRestaurantsAdapter;
import com.tesis_2.Utils.UTRestaurantsSimpleAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;

public class UIRestaurants extends ListActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uirestaurants);
		ArrayList<MORestaurant> lsRest = new ArrayList<MORestaurant>();
		
		try {
			BLRestaurants.fillRestaurants();
			lsRest = BLRestaurants.getLsRest();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setListAdapter( new UTRestaurantsAdapter(this, lsRest));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uirestaurants, menu);
		return true;
	}
	
	public void onListItemClick(ListView l, View v, int position, long id) {
        // Do something when a list item is clicked
		//Intent intent = new Intent(getApplicationContext(), UIAceptarReservaLocal.class);
		//MORestaurant rs = (MORestaurant) getListAdapter().getItem(position);
		//intent.putExtra("RestId", rs.getId());
		//startActivity(intent);
    }
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optAgregar_restaurant:
	        	intent = new Intent(this, UIRegistrarRestaurante.class);
				intent.putExtra("modo", 1);
				startActivity(intent);
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	} 
	
}
